package com.newshub.app.ui.profile

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.Fragment
import com.newshub.app.databinding.FragmentProfileBinding

class ProfileFragment : Fragment() {
    
    private var _binding: FragmentProfileBinding? = null
    private val binding get() = _binding!!
    
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        _binding = FragmentProfileBinding.inflate(inflater, container, false)
        return binding.root
    }
    
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        
        setupClickListeners()
    }
    
    private fun setupClickListeners() {
        // 设置按钮点击事件
        binding.settingsItem.setOnClickListener {
            val intent = Intent(context, com.newshub.app.ui.settings.SettingsActivity::class.java)
            startActivity(intent)
        }
        
        // 关于按钮点击事件
        binding.aboutItem.setOnClickListener {
            Toast.makeText(context, "关于新闻中心应用", Toast.LENGTH_SHORT).show()
            // 这里可以显示关于对话框或跳转到关于页面
            showAboutDialog()
        }
        
        // 意见反馈按钮点击事件
        binding.feedbackItem.setOnClickListener {
            val intent = Intent(context, com.newshub.app.ui.feedback.FeedbackActivity::class.java)
            startActivity(intent)
        }
    }
    
    private fun showAboutDialog() {
        // 创建一个简单的关于对话框
        val builder = androidx.appcompat.app.AlertDialog.Builder(requireContext())
        builder.setTitle("关于新闻中心")
        builder.setMessage("新闻中心 v1.0\n\n这是一个简洁的新闻阅读应用，为您提供最新的新闻资讯。\n\n开发团队：新闻中心团队")
        builder.setPositiveButton("确定") { dialog, _ ->
            dialog.dismiss()
        }
        builder.show()
    }
    
    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}